import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:lcapp/api/interface/home_api.dart';
import 'package:lcapp/api/request/response_data.dart';
import 'package:lcapp/basic/user_info.dart';
import 'package:lcapp/config/const_config.dart';
import 'package:lcapp/data/jy_address_entity.dart';
import 'package:lcapp/data/media_asset_data_entity.dart';
import 'package:lcapp/data/xian_huo_data_entity.dart';
import 'package:lcapp/model/event/event_bus.dart';
import 'package:lcapp/model/level_picker/level_picker.dart';
import 'package:lcapp/model/oss/oss.dart';
import 'package:lcapp/model/param/base_param.dart';
import 'package:lcapp/model/permission/permission_operate.dart';
import 'package:lcapp/model/toast/toast.dart';
import 'package:lcapp/page/home/home_sel_address.dart';
import 'package:lcapp/tools/input_filter.dart';
import 'package:lcapp/widget/asr_app_bar.dart';
import 'package:lcapp/widget/asr_cache_image.dart';
import 'package:flutter_switch/flutter_switch.dart';

class FaBuSoldPage extends StatefulWidget {
  final Map?  arguments; //0 出售 1 采购
  const FaBuSoldPage({Key? key, this.arguments,}) : super(key: key);

  @override
  _FaBuSoldPageState createState() => _FaBuSoldPageState();
}

class _FaBuSoldPageState extends State<FaBuSoldPage> {
  TextEditingController titleController = TextEditingController();
  TextEditingController descontroller = TextEditingController();
  TextEditingController pricecontroller = TextEditingController();
  TextEditingController numcontroller = TextEditingController();
  StreamSubscription? _subscription;

  String? location;
  String? locationStr;
  String? coordinate;
  String? addressName;
  String? adCode;
  List<MediaAssetDataEntity>? assets = [];
  String year='请选择年份';
  List<String> years = [];
  String selPl = '请选择品类';
  int? selPlId;
  List<String> plList = [];
  List pllistIds = [];
  bool isYijia = true;
  List dwList = ['元/每斤','元/每吨'];
  String dwStr = '元/每斤';

  XianHuoDataEntity entity = XianHuoDataEntity();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _subscription = eventBus.on<OssUploadState>().listen((event) {
      if (event.state == 1) {
        if(widget.arguments?['fabuType'] == 0){
          saveSold();
        }else{
          saveCaigou();
        }
      }
    });

    getTypes();
    if(widget.arguments?['id']!=null){
      getDetail();
    }else{
      location = '${userInfo.addressRegin ??''} ${userInfo.addressDetail ?? ''}';
      locationStr = userInfo.addressDetail;
      coordinate = userInfo.coordinate;
    }
  }

  @override
  void dispose() {
    super.dispose();
    _subscription?.cancel();
  }

  getImage(){
    // getAlbumPermission(context, ()async{
    //   List<MediaAssetDataEntity> res = await AsrMediaPicker.pickImg(
    //     showCamera: true,selectCount: 4-assets.length);
    //   if(res!=null){
    //     setState(() {
    //       assets.addAll(res);
    //     });
    //   }
    // });
  }

  getDetail()async{
    showLoading();
    ResponseData res = await HomeAPI.getXianDetail(widget.arguments?['id']);
    hideLoading();
    if(res.code==200){
      entity = XianHuoDataEntity().fromJson(res.data);
      titleController.text = entity.name!;
      descontroller.text = entity.description!;
      pricecontroller.text = entity.price!;
      numcontroller.text = entity.numbers!;
      if(entity.address!=null&&entity.address!.isNotEmpty){
        List arr = entity.address!.split(' ');
        if(arr.length>=4){
          locationStr = arr[3] ?? '';
        }else{
          locationStr = entity.address;
        }
        location = entity.address;
      }
      coordinate = '${entity.longitude},${entity.latitude}';
      isYijia = entity.bargain == 1;
      year = entity.year!;
      addressName = entity.production;
      selPl = entity.typeName!;
      selPlId = entity.type;
      dwStr = entity.productUnit == 1?'元/每斤':'元/每吨';
      if(entity.images!=null&&entity.images!.isNotEmpty){
        for (var element in entity.images!) {
          if(element!=null&&element.isNotEmpty){
            MediaAssetDataEntity img = MediaAssetDataEntity();
            img.type=1;
            img.url = element;
            img.uri = element;
            assets?.add(img);
          }
        }}
    }
    if(mounted){
      setState(() {});
    }
  }

  getTypes()async{

    DateTime today = new DateTime.now();
     int nowYear = today.year;
    for(var i=nowYear-30;i<2099;i++){
      years.add('$i');
    }
    ResponseData res = await HomeAPI.getXianTypes();
    if(res.code==200){
      plList.clear();
      pllistIds.clear();
        List arr = res.data??[];
        arr.forEach((element) {
          plList.add(element['name']);
          pllistIds.add(element['id']);
        });
    }
    if(mounted){setState(() {});}
  }

  saveSold()async{
    Map<String,dynamic> body = {
      'name':titleController.text.trim(),
      'description':descontroller.text.trim(),
      'images':assets?.map((e){
        return e.url;
      }).toList(),
      'address':location,
      'latitude':coordinate!=null? coordinate!.split(',')[1]:null,
      'longitude':coordinate!=null?coordinate!.split(',')[0]:null,
      'numbers':numcontroller.text.trim(),
      'price':pricecontroller.text.trim(),
      'production':addressName,
      'year':year,
      'type':selPlId,
      'typeName':selPlId!=null?selPl:null,
      'id':widget.arguments?['id'],
      'bargain':isYijia?1:0,
      'productUnit':dwStr=='元/每斤'?1:2
    };
    showLoading();
    ResponseData res = await HomeAPI.saveSold(body);
    hideLoading();
    if(res.code==200){
      showToast('发布成功');
      eventBus.fire(FabuState(1));
      Navigator.of(context).pop();
    }
  }

  saveCaigou()async{
    Map<String,dynamic> body = {
      'name':titleController.text.trim(),
      'description':descontroller.text.trim(),
      'address':location,
      'latitude':coordinate!=null? coordinate!.split(',')[1]:null,
      'longitude':coordinate!=null?coordinate!.split(',')[0]:null,
      'numbers':numcontroller.text.trim(),
      'price':pricecontroller.text.trim(),
      'production':addressName,
      'year':year,
      'type':selPlId,
      'id':widget.arguments?['id'],
      'productUnit':dwStr=='元/每斤'?1:2
    };
    showLoading();
    ResponseData res = await HomeAPI.saveCaigou(body);
    hideLoading();
    if(res.code==200){
      showToast('发布成功');
      eventBus.fire(FabuState(1));
      Navigator.of(context).pop();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 1.sw,
      height: 1.sh,
      child: Stack(
        children: [
          Scaffold(
            backgroundColor: bgColor,
            appBar: AsrAppBar(
              titleText: widget.arguments?['fabuType']==0? '发布出售':'发布采购',
              barColor: Colors.white,
              backgroundColor: defaultBarColor,
            ),
            body: Container(
              child: SingleChildScrollView(
                child: GestureDetector(
                  onTap: (){
                    FocusScope.of(context).requestFocus(FocusNode());
                  },
                  child: Container(
                    padding: EdgeInsets.only(bottom: ScreenUtil().bottomBarHeight),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          padding: EdgeInsets.symmetric(horizontal: 30.w),
                          height: 80.w,
                          alignment: Alignment.centerLeft,
                          decoration: BoxDecoration(
                              color: Color(0xffFFD0B9)
                          ),
                          child: Text(BaseParam.soldDesx,
                            style: TextStyle(
                                color: Color(0xffB2440C),
                                fontSize: 25.sp
                            ),),
                        ),
                        Container(
                          height: 85.w,
                          // color: Colors.red,
                          child: TextField(
                            controller: titleController,
                            maxLines: 1,
                            maxLength: 20,
                            style: TextStyle(
                                fontSize: 34.sp
                            ),
                            decoration:  InputDecoration(
                              contentPadding: EdgeInsets.symmetric(horizontal: 30.w),
                              hintText: "描述商品名称、特点",
                              hintStyle: TextStyle(
                                color: const Color(0xFF7F7F7F),
                                fontSize: 34.sp,
                                fontWeight: FontWeight.w500,
                              ),
                              counterText: "",
                              border: const OutlineInputBorder(
                                borderSide: BorderSide.none,
                              ),
                              fillColor: Colors.transparent,
                              filled: true,
                            ),
                          ),
                        ),
                        Container(
                          height: 0.5,
                          color: Color(0xffE9E8E9),
                        ),
                        Container(
                          height: 200.w,
                          child: TextField(
                            controller: descontroller,
                            maxLines: null,
                            maxLength: 100,
                            keyboardType: TextInputType.multiline,
                            style: TextStyle(
                                fontSize: 30.sp
                            ),
                            decoration:  InputDecoration(
                              contentPadding: EdgeInsets.symmetric(horizontal: 30.w),
                              hintText: "详细描述..",
                              hintStyle: TextStyle(
                                color: const Color(0xFF7F7F7F),
                                fontSize: 30.sp,
                                fontWeight: FontWeight.w500,
                              ),
                              counterText: "",
                              border: const OutlineInputBorder(
                                borderSide: BorderSide.none,
                              ),
                              fillColor: Colors.transparent,
                              filled: true,
                            ),
                          ),
                        ),
                        //图片
                        Visibility(child: Container(
                          height: 260.w,
                          padding: EdgeInsets.symmetric(horizontal: 30.w),
                          margin: EdgeInsets.only(top: 30.w),
                          child: ListView.builder(
                              scrollDirection: Axis.horizontal,
                              itemCount: assets!.length<4? assets!.length+1:4,
                              itemBuilder: (context,index){
                                if(index==assets!.length){
                                  return GestureDetector(
                                    onTap: (){
                                      FocusScope.of(context).requestFocus(FocusNode());
                                      getImage();
                                    },
                                    child: ClipRRect(
                                      borderRadius: BorderRadius.circular(10.w),
                                      child: Container(
                                        margin: EdgeInsets.only(right: 20.w),
                                        width: 240.w,
                                        height: 240.w,
                                        color: Colors.white,
                                        alignment: Alignment.center,
                                        child: Image.asset(
                                          'assets/fabu/fabu_add.png',
                                          width: 80.w,
                                          height: 80.w,
                                          fit: BoxFit.fitWidth,
                                        ),
                                      ),
                                    ),
                                  );
                                }
                                return ClipRRect(
                                  borderRadius: BorderRadius.circular(10.w),
                                  child: Container(
                                    margin: EdgeInsets.only(right: 20.w),
                                    width: 240.w,
                                    height: 240.w,
                                    color: Colors.white,
                                    child: Stack(
                                      children: [
                                        Positioned(child: GestureDetector(
                                          onTap: (){

                                          },
                                          child: ASRCacheImage(
                                            image: assets![index].uri!,
                                            fit: BoxFit.cover,
                                          ),
                                        ),left: 0,right: 0,top: 0,bottom: 0,),
                                        Positioned(child: GestureDetector(
                                          onTap: (){
                                            FocusScope.of(context).requestFocus(FocusNode());
                                            setState(() {
                                              assets!.removeAt(index);
                                            });
                                          },
                                          child: Image.asset('assets/home/home_share_close.png',width: 40.w,),
                                        ),right: 0,)
                                      ],
                                    ),
                                  ),
                                );
                              }
                          ),
                        ),visible: widget.arguments?['fabuType']==0,),
                        GestureDetector(
                          onTap: (){
                            Navigator.of(context).pushNamed('MinAddressListPage',arguments: {
                              'callBack':(value){
                                setState(() {
                                  if(value!=null){
                                    JyAddressEntity entity = value;
                                    coordinate = '${entity.longitude},${entity.latitude}';
                                    location = '${entity.province} ${entity.city} ${entity.region} ${entity.detailAddress}';
                                    locationStr = entity.detailAddress;

                                  }
                                });
                              }
                            });
                            // Navigator.of(context).pushNamed('AmapViewPage').then((value){
                            //   if(value is Map){
                            //     print('选择地址===' + value.toString());
                            //     setState(() {
                            //       coordinate = value['coordinate'];
                            //       location = value['locationName'];
                            //     });
                            //   }
                            // });
                          },
                          child: Container(
                            // height: 60.w,
                            padding: EdgeInsets.symmetric(horizontal: 20.w,vertical: 10.w),
                            margin: EdgeInsets.only(left: 30.w,top: 30.w,bottom: 30.w),
                            decoration: BoxDecoration(
                                color: Color(0xffEEEEEE),
                                border: Border.all(color: Color(0xffD8D8D8),width: 1),
                                borderRadius: BorderRadius.circular(60.w)
                            ),
                            child: Row(
                              mainAxisSize: MainAxisSize.min,
                              children: [
                                Image.asset("assets/fabu/fabu_dt.png",width: 20.w,),
                                SizedBox(width: 10.w,),
                                Container(
                                  constraints: BoxConstraints(
                                    maxWidth: 600.w,
                                  ),
                                  child: Text(locationStr?? '请选择经营地址',),
                                )
                              ],
                            ),
                          ),
                        ),
                        Container(
                          padding: EdgeInsets.symmetric(horizontal: 30.w),
                          height:90.w,
                          child: Column(
                            children: [
                              Expanded(child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Text('品类',style: TextStyle(
                                      color: Color(0xff1A051D),
                                      fontSize: 30.sp,
                                      fontWeight: FontWeight.w500
                                  ),),
                                  SizedBox(width: 20.w,),
                                  Expanded(child: GestureDetector(
                                    onTap: (){
                                      FocusScope.of(context).requestFocus(FocusNode());
                                      JhPickerTool.showStringPicker(
                                        context,
                                        title: '请选择品类',
                                        data: plList,
                                        clickCallBack: _selectPLSex,
                                        // pickerType: AsrPickerType.PICKERORANGETHEME,
                                      );
                                    },
                                    child: Container(
                                      color: Colors.transparent,
                                      alignment: Alignment.centerRight,
                                      child: Text(selPl,style: TextStyle(
                                          color: Color(0xff848484),
                                          fontSize: 30.sp,
                                          fontWeight: FontWeight.w500
                                      ),),
                                    ),
                                  ))
                                ],
                              ),),
                              Container(
                                height: 0.5,
                                color: Color(0xffE9E8E9),
                              )
                            ],
                          ),
                        ),
                        Container(
                          padding: EdgeInsets.symmetric(horizontal: 30.w),
                          height:90.w,
                          child: Column(
                            children: [
                              Expanded(child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Text('年份',style: TextStyle(
                                      color: Color(0xff1A051D),
                                      fontSize: 30.sp,
                                      fontWeight: FontWeight.w500
                                  ),),
                                  SizedBox(width: 20.w,),
                                  Expanded(child: GestureDetector(
                                    onTap: (){
                                      FocusScope.of(context).requestFocus(FocusNode());
                                      JhPickerTool.showStringPicker(
                                        context,
                                        title: '请选择年份',
                                        data: years,
                                        normalIndex: 30,
                                        clickCallBack: _selectYear,
                                        // pickerType: AsrPickerType.PICKERORANGETHEME,
                                      );
                                    },
                                    child: Container(
                                      color: Colors.transparent,
                                      alignment: Alignment.centerRight,
                                      child: Text(year,style: TextStyle(
                                          color: Color(0xff848484),
                                          fontSize: 30.sp,
                                          fontWeight: FontWeight.w500
                                      ),),
                                    ),
                                  ))
                                ],
                              ),),
                              Container(
                                height: 0.5,
                                color: Color(0xffE9E8E9),
                              )
                            ],
                          ),
                        ),
                        Container(
                          padding: EdgeInsets.symmetric(horizontal: 30.w),
                          height:90.w,
                          child: Column(
                            children: [
                              Expanded(child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Text('产地',style: TextStyle(
                                      color: Color(0xff1A051D),
                                      fontSize: 30.sp,
                                      fontWeight: FontWeight.w500
                                  ),),
                                  SizedBox(width: 20.w,),
                                  Expanded(child: GestureDetector(
                                    onTap: ()async{
                                      FocusScope.of(context).requestFocus(FocusNode());
                                      SmartDialog.show(
                                        alignment: Alignment.bottomCenter,
                                        clickMaskDismiss: true,
                                        maskColor: Color.fromRGBO(0, 0, 0, 0.5), builder: (BuildContext context) {
                                          return HomeSelAddressPage(selAddress: (pName,cName,name,code,){
                                            setState(() {
                                              addressName = '$pName $cName $name';
                                              adCode = code;
                                            });
                                          });
                                      },
                                      );
                                    },
                                    child: addressName==null? Container(
                                      alignment: Alignment.centerRight,
                                      child: Image.asset('assets/fabu/fabu_cd.png',height: 55.w,),
                                    ):Container(
                                      color: Colors.transparent,
                                      alignment: Alignment.centerRight,
                                      child: Text(addressName!,style: TextStyle(
                                          color: Color(0xff848484),
                                          fontSize: 30.sp,
                                          fontWeight: FontWeight.w500
                                      )),
                                    ),
                                  ))
                                ],
                              ),),
                              Container(
                                height: 0.5,
                                color: Color(0xffE9E8E9),
                              )
                            ],
                          ),
                        ),
                        Container(
                          padding: EdgeInsets.symmetric(horizontal: 30.w),
                          height:90.w,
                          child: Column(
                            children: [
                              Expanded(child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Image.asset('assets/fabu/fabu_price.png',height: 40.w,),
                                  SizedBox(width: 20.w,),
                                  Text('价格',style: TextStyle(
                                      color: Color(0xff1A051D),
                                      fontSize: 30.sp,
                                      fontWeight: FontWeight.w500
                                  ),),
                                  SizedBox(width: 20.w,),
                                  Expanded(child: GestureDetector(
                                    onTap: (){
                                      FocusScope.of(context).requestFocus(FocusNode());
                                    },
                                    child: Container(
                                        alignment: Alignment.centerRight,
                                        child: TextField(
                                          controller: pricecontroller,
                                          maxLines: 1,
                                          keyboardType: TextInputType.numberWithOptions(decimal: true),
                                          inputFormatters: [
                                            PrecisionLimitFormatter(2),
                                            FilteringTextInputFormatter.allow(RegExp('[0-9.,]+'))
                                          ],
                                          autocorrect: true,
                                          autofocus: false,
                                          textAlign: TextAlign.right,
                                          decoration:  InputDecoration(
                                            contentPadding: EdgeInsets.only(left: 17.w),
                                            hintText: "请输入价格/元",
                                            hintStyle: TextStyle(
                                              color: const Color(0xFFAEAEAE),
                                              fontSize: 26.sp,
                                              fontWeight: FontWeight.w500,
                                            ),
                                            counterText: "",
                                            border: const OutlineInputBorder(
                                              borderSide: BorderSide.none,
                                            ),
                                            fillColor: Colors.transparent,
                                            filled: true,
                                          ),
                                        )
                                    ),
                                  )),
                                  Container(
                                    width: 1,
                                    height: 35.w,
                                    color: Color(0xff999999),
                                    margin: EdgeInsets.symmetric(horizontal: 20.w),
                                  ),
                                  GestureDetector(
                                    onTap: (){
                                      FocusScope.of(context).requestFocus(FocusNode());
                                      JhPickerTool.showStringPicker(
                                        context,
                                        title: '请选择单位',
                                        data: dwList,
                                        clickCallBack: _selectDWSex,
                                        // pickerType: AsrPickerType.PICKERORANGETHEME,
                                      );
                                    },
                                    child: Row(
                                      children: [
                                        Text(dwStr,style: TextStyle(
                                            color: Color(0xff333333),
                                            fontSize: 26.sp,
                                            fontWeight: FontWeight.w500
                                        ),),
                                        Icon(Icons.arrow_drop_down,size: 35.sp,color: Color(0xff333333),)
                                      ],
                                    ),
                                  )
                                ],
                              ),),
                              Container(
                                height: 0.5,
                                color: Color(0xffE9E8E9),
                              )
                            ],
                          ),
                        ),
                        Container(
                          padding: EdgeInsets.symmetric(horizontal: 30.w),
                          height:90.w,
                          child: Column(
                            children: [
                              Expanded(child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Image.asset('assets/fabu/fabu_num.png',height: 40.w,),
                                  SizedBox(width: 20.w,),
                                  Text('数量',style: TextStyle(
                                      color: Color(0xff1A051D),
                                      fontSize: 30.sp,
                                      fontWeight: FontWeight.w500
                                  ),),
                                  SizedBox(width: 20.w,),
                                  Expanded(child: GestureDetector(
                                    onTap: (){
                                      FocusScope.of(context).requestFocus(FocusNode());
                                    },
                                    child: Container(
                                        alignment: Alignment.centerRight,
                                        child: TextField(
                                          controller: numcontroller,
                                          maxLines: 1,
                                          autocorrect: true,
                                          autofocus: false,
                                          keyboardType: TextInputType.numberWithOptions(decimal: true),
                                          inputFormatters: [
                                            PrecisionLimitFormatter(0),
                                            FilteringTextInputFormatter.allow(RegExp('[0-9]+'))
                                          ],
                                          textAlign: TextAlign.right,
                                          decoration:  InputDecoration(
                                            contentPadding: EdgeInsets.only(left: 17.w),
                                            hintText: "请输入数量/吨",
                                            hintStyle: TextStyle(
                                              color: const Color(0xFFAEAEAE),
                                              fontSize: 26.sp,
                                              fontWeight: FontWeight.w500,
                                            ),
                                            counterText: "",
                                            border: const OutlineInputBorder(
                                              borderSide: BorderSide.none,
                                            ),
                                            fillColor: Colors.transparent,
                                            filled: true,
                                          ),
                                        )
                                    ),
                                  )),
                                  // Container(
                                  //   padding: EdgeInsets.symmetric(horizontal: 20.w),
                                  //   child: Text('吨',style: TextStyle(
                                  //       color: Color(0xff666666),
                                  //       fontSize: 26.sp,
                                  //       fontWeight: FontWeight.w500
                                  //   ),),
                                  // )
                                ],
                              ),),
                              Container(
                                height: 0.5,
                                color: Color(0xffE9E8E9),
                              )
                            ],
                          ),
                        ),
                        Visibility(child: Container(
                          padding: EdgeInsets.symmetric(horizontal: 30.w),
                          height:90.w,
                          child: Column(
                            children: [
                              Expanded(child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Text('是否开启议价',style: TextStyle(
                                      color: Color(0xff1A051D),
                                      fontSize: 30.sp,
                                      fontWeight: FontWeight.w500
                                  ),),
                                  SizedBox(width: 20.w,),
                                  FlutterSwitch(
                                    width: 100.w,
                                    height: 60.w,
                                    value: isYijia,
                                    activeColor:defaultBarColor,
                                    borderRadius: 30.0,
                                    onToggle: (value) {
                                      FocusScope.of(context).requestFocus(FocusNode());
                                      setState(() {
                                        isYijia  = value;
                                      });
                                    },
                                  )
                                ],
                              ),),
                              Container(
                                height: 0.5,
                                color: Color(0xffE9E8E9),
                              )
                            ],
                          ),
                        ),visible: widget.arguments?['fabuType']==0,),
                        SizedBox(height: 40.w,),
                        GestureDetector(
                          onTap: (){
                            FocusScope.of(context).requestFocus(FocusNode());
                            if(titleController.text.trim().isEmpty){
                              showToast('请完善商品名称、特点信息');
                              return;
                            }
                            if(titleController.text.length>20){
                              showToast('名称不能超过20个字');
                              return;
                            }
                            if(descontroller.text.trim().isEmpty){
                              showToast('请完善详细描述信息');
                              return;
                            }
                            if(descontroller.text.length>100){
                              showToast('描述不能超过100个字');
                              return;
                            }
                            if(widget.arguments?['fabuType']==0&&assets!.length<1){
                              showToast('请先上传图片信息');
                              return;
                            }
                            if(locationStr == null || locationStr!.isEmpty){
                              showToast('请选择经营地址');
                              return;
                            }
                            if(selPl.isEmpty){
                              showToast('请完善商品品类信息');
                              return;
                            }
                            if(year.trim().isEmpty){
                              showToast('请完善商品年份信息');
                              return;
                            }
                            if(addressName == null || addressName!.isEmpty){
                              showToast('请完善商品产地信息');
                              return;
                            }
                            if(pricecontroller.text.trim().isEmpty){
                              showToast('请完善商品价格信息');
                              return;
                            }
                            if(numcontroller.text.trim().isEmpty){
                              showToast('请完善商品数量信息');
                              return;
                            }
                            RegExp exp = RegExp(
                                r'((13[0-9])|(14[0-9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\d{8}');
                            RegExpMatch? matchs = exp.firstMatch(titleController.text);
                            RegExpMatch? matchs1 = exp.firstMatch(descontroller.text);
                            if(matchs!=null||matchs1!=null){
                              showToast('请不要输入手机号登敏感信息!');
                              return;
                            }

                            if(assets!.length>0){
                              // AsrOss.ossUploadVideo(assets);
                            }else{
                              if(widget.arguments?['fabuType']==0){
                                saveSold();
                              }else{
                                saveCaigou();
                              }
                            }

                          },
                          child: Container(
                            height: 100.w,
                            margin: EdgeInsets.symmetric(horizontal: 30.w),
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                color: Color(0xffEA6B2B),
                                borderRadius: BorderRadius.circular(10.w)
                            ),
                            child: Text(widget.arguments?['fabuType']==0?'发布出售':'发布采购',style: TextStyle(
                                color: Colors.white,
                                fontSize: 30.sp,
                                fontWeight: FontWeight.w500
                            ),),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ),
          // Visibility(child: DraggableFloatWidget(
          //   child: Container(
          //     height: 100,
          //     width: 100,
          //     decoration: BoxDecoration(
          //         color: defaultBarColor,
          //         borderRadius: BorderRadius.circular(100)
          //     ),
          //     alignment: Alignment.center,
          //    child: Image.asset("assets/fabu/fabu_guide_video.png",width: 100,),
          //   ),
          //   config:  DraggableFloatWidgetBaseConfig(
          //       isFullScreen: true,
          //       initPositionYInTop: false,
          //       initPositionXInLeft: false,
          //       borderTop: 100,
          //       borderBottom: 100
          //   ),
          //   onTap: () {
          //     MediaAssetDataEntity entity = MediaAssetDataEntity();
          //     entity.type=2;
          //     entity.uri = BaseParam.fabuSoldURL;
          //     Navigator.of(context).pushNamed('MediaViewer', arguments: {
          //       'assets': [entity],
          //       'currentIndex': 0
          //     });
          //   },
          // ),visible: BaseParam.fabuSoldURL!=null,)
        ],
      ),
    );
  }

  _selectPLSex(int index, dynamic selectDate) {
    setState(() {
      selPl = selectDate;
      selPlId = pllistIds[index];
    });
  }
  _selectYear(int index, dynamic selectDate) {
    setState(() {
      year = selectDate;
    });
  }
  _selectDWSex(int index, dynamic selectDate){
    setState(() {
      dwStr = selectDate;
    });
  }
}
